package cj.web.tb.dao;
/*
 *  
 *  
*/
import java.util.List;
import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.tb.domain.TBSchool;

/**
 * 
 * @author 
 *
 */
@DAO
public interface TBSchoolDAO{
	
	@SQL("SELECT * FROM TBSchool WHERE deleteFlag=1 #if(:t.areaName != null){ AND areaName=:t.areaName }"
        	+ " #if(:t.keywords!=null){and (id like '%##(:t.keywords)%' or "
        	+ "address like '%##(:t.keywords)%' or "
        	+ "code like '%##(:t.keywords)%' or "
        	+ "owner like '%##(:t.keywords)%' or "
        	+ "phone like '%##(:t.keywords)%' or "
        	+ "president like '%##(:t.keywords)%') } "
			+" ORDER BY id DESC LIMIT :t.start,:t.length ")
    List<TBSchool> query(@SQLParam("t") TBSchool tBSchool);
	
	@SQL("SELECT count(1) FROM TBSchool WHERE deleteFlag=1 #if(:t.areaName != null){ AND areaName=:t.areaName }"
        	+ " #if(:t.keywords!=null){and (id like '%##(:t.keywords)%' or "
        	+ "address like '%##(:t.keywords)%' or "
        	+ "code like '%##(:t.keywords)%' or "
        	+ "owner like '%##(:t.keywords)%' or "
        	+ "phone like '%##(:t.keywords)%' or "
        	+ "president like '%##(:t.keywords)%') } ")
	int querySize(@SQLParam("t") TBSchool tBSchool);
    
    @SQL("SELECT * FROM TBSchool WHERE id=:1 ")
    TBSchool queryById(int id);
    
    @SQL("SELECT * FROM TBSchool WHERE areaName=:1 and name=:2 ")
    TBSchool queryByAreaName(String areaName,String name);
    
    @SQL("SELECT name,address,phone,president FROM TBSchool WHERE areaName=:1 ")
    List<TBSchool> querySchoollisByAreaName(String areaName);
    
    @SQL("INSERT INTO TBSchool (areaName,name,address,code,type,owner,phone,president,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.areaName,:t.name,:t.address,:t.code,:t.type,:t.owner,:t.phone,:t.president,1,now(),:t.createUser,now(),:t.updateUser) ")
    void create(@SQLParam("t") TBSchool tBSchool);
	
	@SQL("UPDATE TBSchool SET areaName=:t.areaName,name=:t.name,address=:t.address,code=:t.code,type=:t.type,owner=:t.owner,phone=:t.phone,president=:t.president,updateAt=now(),updateUser=:t.updateUser WHERE id=:t.id ")
    void update(@SQLParam("t") TBSchool tBSchool);
    
    @SQL("UPDATE TBSchool SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
}